/*     */ package com.zimbra.qa.unittest;
/*     */ 
/*     */ import com.zimbra.common.account.Key.AccountBy;
/*     */ import com.zimbra.common.account.Key.CacheEntryBy;
/*     */ import com.zimbra.common.net.SocketFactories;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.AuthToken;
/*     */ import com.zimbra.cs.account.CalendarResource;
/*     */ import com.zimbra.cs.account.Cos;
/*     */ import com.zimbra.cs.account.DistributionList;
/*     */ import com.zimbra.cs.account.Domain;
/*     */ import com.zimbra.cs.account.DynamicGroup;
/*     */ import com.zimbra.cs.account.Group;
/*     */ import com.zimbra.cs.account.GuestAccount;
/*     */ import com.zimbra.cs.account.NamedEntry;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.account.Provisioning.CacheEntry;
/*     */ import com.zimbra.cs.account.Server;
/*     */ import com.zimbra.cs.account.Zimlet;
/*     */ import com.zimbra.qa.unittest.prov.ldap.ACLTestUtil.KeyAuthToken;
/*     */ import com.zimbra.soap.admin.type.CacheEntryType;
/*     */ import java.io.PrintStream;
/*     */ import java.util.ArrayList;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public abstract class TestProv
/*     */   extends TestLdap
/*     */ {
/*  48 */   protected static final String TEST_ID = ;
/*  49 */   protected static final String BASE_DOMAIN_NAME = TestLdap.baseDomainName(TestProv.class);
/*     */   
/*     */   protected static final String PASSWORD = "test123";
/*     */   
/*     */   protected static Provisioning sSoapProv;
/*     */   protected static Provisioning sLdapProv;
/*  55 */   private static int sSequence = 1;
/*     */   
/*     */ 
/*  58 */   List<NamedEntry> mCreatedEntries = new ArrayList();
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*  64 */   List<NamedEntry> mCreatedDomains = new ArrayList();
/*     */   
/*  66 */   protected Provisioning mProv = sLdapProv;
/*     */   
/*     */   static {
/*     */     try {
/*  70 */       SocketFactories.registerProtocols();
/*  71 */       sSoapProv = TestProvisioningUtil.getSoapProvisioning();
/*  72 */       sLdapProv = TestProvisioningUtil.getLdapProvisioning();
/*     */     } catch (Exception e) {
/*  74 */       System.out.println("*** init failed ***");
/*  75 */       e.printStackTrace();
/*  76 */       System.exit(1);
/*     */     }
/*     */   }
/*     */   
/*     */   protected void useSoapProv() {
/*  81 */     this.mProv = sSoapProv;
/*     */   }
/*     */   
/*     */   protected void useLdapProv() {
/*  85 */     this.mProv = sLdapProv;
/*     */   }
/*     */   
/*     */   private static synchronized String nextSeq()
/*     */   {
/*  90 */     return "" + sSequence++;
/*     */   }
/*     */   
/*     */   private String genDomainName() {
/*  94 */     return nextSeq() + "." + BASE_DOMAIN_NAME;
/*     */   }
/*     */   
/*     */   private String genAccountName() {
/*  98 */     return "acct-" + nextSeq() + "." + BASE_DOMAIN_NAME;
/*     */   }
/*     */   
/*     */   private String genCalendarResourceName() {
/* 102 */     return "cr-" + nextSeq() + "." + BASE_DOMAIN_NAME;
/*     */   }
/*     */   
/*     */   private String genDistributionListName() {
/* 106 */     return "dl-" + nextSeq() + "." + BASE_DOMAIN_NAME;
/*     */   }
/*     */   
/*     */   private String genDynamicGroupName() {
/* 110 */     return "group-" + nextSeq() + "." + BASE_DOMAIN_NAME;
/*     */   }
/*     */   
/*     */   private String genCosName() {
/* 114 */     return "cos-" + nextSeq() + "." + BASE_DOMAIN_NAME;
/*     */   }
/*     */   
/*     */   private String genServerName() {
/* 118 */     return "server-" + nextSeq() + "." + BASE_DOMAIN_NAME;
/*     */   }
/*     */   
/*     */   private String genXMPPComponentName() {
/* 122 */     return "xmpp-" + nextSeq() + "." + BASE_DOMAIN_NAME;
/*     */   }
/*     */   
/*     */   private String genZimletName() {
/* 126 */     return "zimlet-" + nextSeq() + "." + BASE_DOMAIN_NAME;
/*     */   }
/*     */   
/*     */   protected String getEmailLocalpart(Account acct) {
/* 130 */     return getEmailLocalpart(acct.getName());
/*     */   }
/*     */   
/*     */   protected String getEmailLocalpart(DistributionList dl) {
/* 134 */     return getEmailLocalpart(dl.getName());
/*     */   }
/*     */   
/*     */   protected String getEmailLocalpart(String email) {
/* 138 */     String[] parts = email.split("@");
/* 139 */     return parts[0];
/*     */   }
/*     */   
/*     */   protected Account getGlobalAdminAcct() throws ServiceException {
/* 143 */     return this.mProv.get(Key.AccountBy.name, TestUtil.getAddress("admin"));
/*     */   }
/*     */   
/*     */   protected Domain createDomain() throws Exception {
/* 147 */     Domain domain = this.mProv.createDomain(genDomainName(), new HashMap());
/* 148 */     this.mCreatedDomains.add(domain);
/* 149 */     return domain;
/*     */   }
/*     */   
/*     */   protected Account createAccount(String localpart, Domain domain, Map<String, Object> attrs) throws Exception {
/* 153 */     if (domain == null) {
/* 154 */       domain = createDomain();
/*     */     }
/* 156 */     String email = localpart + "@" + domain.getName();
/* 157 */     Account acct = this.mProv.createAccount(email, "test123", attrs);
/* 158 */     this.mCreatedEntries.add(acct);
/* 159 */     return acct;
/*     */   }
/*     */   
/*     */   protected Account createUserAccount(String localpart, Domain domain) throws Exception {
/* 163 */     return createAccount(localpart, domain, null);
/*     */   }
/*     */   
/*     */   protected Account createUserAccount(Domain domain) throws Exception {
/* 167 */     String localpart = genAccountName();
/* 168 */     return createAccount(localpart, domain, null);
/*     */   }
/*     */   
/*     */   protected Account createDelegatedAdminAccount(String localpart, Domain domain) throws Exception {
/* 172 */     Map<String, Object> attrs = new HashMap();
/* 173 */     attrs.put("zimbraIsDelegatedAdminAccount", "TRUE");
/* 174 */     return createAccount(localpart, domain, attrs);
/*     */   }
/*     */   
/*     */   protected Account createDelegatedAdminAccount(Domain domain) throws Exception {
/* 178 */     String localpart = genAccountName();
/* 179 */     return createDelegatedAdminAccount(localpart, domain);
/*     */   }
/*     */   
/*     */   protected Account createGuestAccount(String email, String password) {
/* 183 */     return new GuestAccount(email, password);
/*     */   }
/*     */   
/*     */   protected Account createKeyAccount(String name, String accesKey) {
/* 187 */     AuthToken authToken = new ACLTestUtil.KeyAuthToken(name, accesKey);
/* 188 */     return new GuestAccount(authToken);
/*     */   }
/*     */   
/*     */   protected Account anonAccount() {
/* 192 */     return GuestAccount.ANONYMOUS_ACCT;
/*     */   }
/*     */   
/*     */   protected CalendarResource createCalendarResource(String localpart, Domain domain) throws Exception {
/* 196 */     Map<String, Object> attrs = new HashMap();
/* 197 */     attrs.put("displayName", localpart);
/* 198 */     attrs.put("zimbraCalResType", "Equipment");
/*     */     
/* 200 */     String email = localpart + "@" + domain.getName();
/* 201 */     CalendarResource cr = this.mProv.createCalendarResource(email, "test123", attrs);
/* 202 */     this.mCreatedEntries.add(cr);
/* 203 */     return cr;
/*     */   }
/*     */   
/*     */   protected CalendarResource createCalendarResource(Domain domain) throws Exception {
/* 207 */     String localpart = genCalendarResourceName();
/* 208 */     return createCalendarResource(localpart, domain);
/*     */   }
/*     */   
/*     */   protected Cos createCos() throws Exception {
/* 212 */     Cos cos = this.mProv.createCos(genCosName(), null);
/* 213 */     this.mCreatedEntries.add(cos);
/* 214 */     return cos;
/*     */   }
/*     */   
/*     */   private DistributionList createDistributionList(String localpart, Domain domain, Map<String, Object> attrs) throws Exception {
/* 218 */     if (domain == null) {
/* 219 */       domain = createDomain();
/*     */     }
/* 221 */     String email = localpart + "@" + domain.getName();
/* 222 */     DistributionList dl = this.mProv.createDistributionList(email, attrs);
/* 223 */     this.mCreatedEntries.add(dl);
/* 224 */     return dl;
/*     */   }
/*     */   
/*     */   protected DistributionList createUserDistributionList(String localpart, Domain domain) throws Exception {
/* 228 */     return createDistributionList(localpart, domain, new HashMap());
/*     */   }
/*     */   
/*     */   protected DistributionList createUserDistributionList(Domain domain) throws Exception {
/* 232 */     String localpart = genDistributionListName();
/* 233 */     return createUserDistributionList(localpart, domain);
/*     */   }
/*     */   
/*     */   protected DistributionList createAdminDistributionList(String localpart, Domain domain) throws Exception
/*     */   {
/* 238 */     Map<String, Object> attrs = new HashMap();
/* 239 */     attrs.put("zimbraIsAdminGroup", "TRUE");
/* 240 */     return createDistributionList(localpart, domain, attrs);
/*     */   }
/*     */   
/*     */   protected DistributionList createAdminDistributionList(Domain domain) throws Exception {
/* 244 */     String localpart = genDistributionListName();
/* 245 */     return createAdminDistributionList(localpart, domain);
/*     */   }
/*     */   
/*     */   private DynamicGroup createDynamicGroup(String localpart, Domain domain, Map<String, Object> attrs) throws Exception
/*     */   {
/* 250 */     if (domain == null) {
/* 251 */       domain = createDomain();
/*     */     }
/*     */     
/* 254 */     String email = localpart + "@" + domain.getName();
/* 255 */     DynamicGroup dynGroup = this.mProv.createDynamicGroup(email, attrs);
/* 256 */     this.mCreatedEntries.add(dynGroup);
/* 257 */     return dynGroup;
/*     */   }
/*     */   
/*     */   protected DynamicGroup createUserDynamicGroup(String localpart, Domain domain) throws Exception {
/* 261 */     return createDynamicGroup(localpart, domain, new HashMap());
/*     */   }
/*     */   
/*     */   protected DynamicGroup createUserDynamicGroup(Domain domain) throws Exception {
/* 265 */     String localpart = genDynamicGroupName();
/* 266 */     return createUserDynamicGroup(localpart, domain);
/*     */   }
/*     */   
/*     */   protected DynamicGroup createAdminDynamicGroup(String localpart, Domain domain) throws Exception {
/* 270 */     Map<String, Object> attrs = new HashMap();
/* 271 */     attrs.put("zimbraIsAdminGroup", "TRUE");
/* 272 */     return createDynamicGroup(localpart, domain, attrs);
/*     */   }
/*     */   
/*     */   protected DynamicGroup createAdminDynamicGroup(Domain domain) throws Exception {
/* 276 */     String localpart = genDynamicGroupName();
/* 277 */     return createAdminDynamicGroup(localpart, domain);
/*     */   }
/*     */   
/*     */   protected Server createServer() throws Exception {
/* 281 */     Server server = this.mProv.createServer(genServerName(), new HashMap());
/* 282 */     this.mCreatedEntries.add(server);
/* 283 */     return server;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   protected Zimlet createZimlet()
/*     */     throws Exception
/*     */   {
/* 293 */     Map<String, Object> attrs = new HashMap();
/* 294 */     attrs.put("zimbraZimletVersion", "1.0");
/* 295 */     Zimlet zimlet = this.mProv.createZimlet(genZimletName(), attrs);
/* 296 */     this.mCreatedEntries.add(zimlet);
/* 297 */     return zimlet;
/*     */   }
/*     */   
/*     */   protected void flushCache(Account acct) throws Exception {
/* 301 */     Provisioning.CacheEntry[] entries = new Provisioning.CacheEntry[1];
/* 302 */     entries[0] = new Provisioning.CacheEntry(Key.CacheEntryBy.name, acct.getName());
/* 303 */     this.mProv.flushCache(CacheEntryType.account, entries);
/*     */   }
/*     */   
/*     */   private void deleteEntry(NamedEntry entry) throws Exception {
/* 307 */     if ((entry instanceof Account)) {
/* 308 */       this.mProv.deleteAccount(entry.getId());
/* 309 */     } else if ((entry instanceof CalendarResource)) {
/* 310 */       this.mProv.deleteCalendarResource(entry.getId());
/* 311 */     } else if ((entry instanceof Cos)) {
/* 312 */       this.mProv.deleteCos(entry.getId());
/* 313 */     } else if ((entry instanceof Group)) {
/* 314 */       this.mProv.deleteGroup(entry.getId());
/* 315 */     } else if ((entry instanceof Domain)) {
/* 316 */       this.mProv.deleteDomain(entry.getId());
/* 317 */     } else if ((entry instanceof Server)) {
/* 318 */       this.mProv.deleteServer(entry.getId());
/* 319 */     } else if ((entry instanceof Zimlet)) {
/* 320 */       this.mProv.deleteZimlet(entry.getName());
/*     */     } else {
/* 322 */       throw new Exception("not yet implemented");
/*     */     }
/*     */   }
/*     */   
/*     */   protected void deleteAllEntries()
/*     */     throws Exception
/*     */   {
/* 329 */     for (NamedEntry entry : this.mCreatedEntries)
/* 330 */       deleteEntry(entry);
/* 331 */     this.mCreatedEntries.clear();
/*     */     
/* 333 */     for (NamedEntry entry : this.mCreatedDomains)
/* 334 */       deleteEntry(entry);
/* 335 */     this.mCreatedDomains.clear();
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/qa/unittest/TestProv.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */